home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / dbpcxl15.zip / PCXLIB.DOC < prev    next >
Text File  |  1992-01-26  |  7KB  |  182 lines

  1. ------------------------------------------------------------------------------
  2.                   pcxlib v1.5   by Dave Boynton
  3.                                 (c) 1991
  4. ------------------------------------------------------------------------------
  5.         This library is hereby placed in the public domain. However, if you'd
  6. like to make a contribution to my efforts to provide a quality product, my
  7. address is:
  8.         David Boynton
  9.         8083 Budding Br Rd, T-3
  10.         Glen Burnie, MD 21061-5077
  11. Any size donation would be welcome.
  12.  
  13. ------------------------------------------------------------------------------
  14.  
  15.         This library currently only supports 256 color pcx files.  There are
  16. routines here for 16 color and monochrome files, but none have been tested.
  17. That will be in the next release. Writing to pcx files is now implemented and 
  18. tested, although there is no read/modify/write setup.
  19.  
  20. ------------------------------------------------------------------------------
  21.  
  22.         Using the library is simple. Follow these steps and you can't go
  23. wrong (famous last words):
  24.         1. Insert '#include "pcxlib.h"' in your source code.
  25.         2. Insert 'pcxlib.obj' and 'videof.lib' in your project file, if
  26.            using TurboC IDE, or insert in your makefile, command line, or
  27.            library, if using something else.
  28.         3. Declare pointers to PCXF, a structure that holds key information
  29.            about open pcx files. I'll use 'pfile' in this walk-through, so
  30.            that would be:
  31.                  PCXF *pfile;
  32.         4. Choose a debug filename and insert 'Start_pcxdebug(filename);'
  33.            in an early part of your program, IF you want the library to
  34.            output debugging information. For example: 
  35.                  Start_pcxdebug("pcx.dbg");
  36.            Remember, this is optional; nothing bad will happen if you don't
  37.            do this.
  38.         5. Open pcx files with something like:
  39.                  pfile=fopenPCXr("blast256.pcx");
  40.         6. Read from the pcx file with either  fread8PCX() or fdisp8PCX().
  41.            The latter assumes the use of my vidlib library to set the video
  42.            mode. That isn't strictly necessary, all you need do is ensure
  43.            that _screen_start, _screen_width, and _screen_length are properly
  44.            updated prior to calling fdisp8PCX().  For mode 13h (320x200 by 256
  45.            colors), these values should be 0xA0000000L, 320, and 200, 
  46.            respectively. These variables are declared as externs in vidlib.h.
  47.         7. When done, close the file with fclosePCX(pfile), which not only
  48.            closes the file, but frees the memory allocated to hold the 
  49.            structures.
  50.         8. If you opened the pcxdebug file, close it with 'Close_pcxdebug();'.
  51.            
  52.         See showpcx.c for a much more readable example.
  53.  
  54. /* pcxlib.h */
  55. #if !defined(__LARGE__) && !defined(__HUGE__)
  56. #error Wrong memory model
  57. #endif
  58.  
  59. #ifndef PCX_H                      /* don't do more than once */
  60. #define PCX_H
  61.  
  62. #define PCXLIB_VERSION         "1.5"
  63.  
  64. #define ALIGN_DWORD(x) (((x)+3)/4 * 4)
  65. #define What_WPlanes    (SQread_reg(2))
  66.  
  67. #define PCXUNK             -1        /* unknown/invalid */
  68. #define PCXMONO             0
  69. #define PCX4colors          1
  70. #define PCX16colors         2
  71. #define PCX256colors        3
  72.  
  73. struct PCXRGB {
  74.        unsigned char r, g, b;
  75. };
  76.  
  77. typedef struct {
  78.         char               MagicId;
  79.         char               Version;
  80.         char               Encoding;
  81.         char               BitsPixel;
  82.         int                Xmin, Ymin;
  83.         int                Xmax, Ymax;
  84.         int                Hres, Vres;
  85.         struct PCXRGB      Palette[16];   /* used only on 16 color pcx's */
  86.         char               Reserved;
  87.         char               Planes;
  88.         unsigned int       bytesline;
  89.         int                PaletteInfo;
  90.         char               Filler[58];
  91. } PCXH;
  92.  
  93. #define  MAXAREA          65520L       /* 64k - 16 bytes (for malloc) */
  94.  
  95. typedef struct {
  96.        char              *name;
  97.        FILE              *fp;
  98.        PCXH              *h;
  99.        unsigned char     *palette; /* for 256 color pcx's w/palette */
  100.        long              *marks;   /* set to NULL when marks not set */
  101.        unsigned char     *buffer;  /* scan line buffer */
  102.        int               next_scan,buffer_scan;
  103.  
  104.        int               type;    /* PCXUNK= -1 =unknown/invalid
  105.                                      PCXMONO= 0 =mono
  106.                                      PCX4colors     1 =4  color
  107.                                      PCX16colors=   2 =16 color seg/line
  108.                                      PCX256colors=  3 =256 color  */
  109.        unsigned          w, l;
  110.        char              cw, cl;
  111.        long              image_size;
  112.        int               read_or_write;  /* 0 = readonly, 1 = writeonly */
  113.        unsigned          num_marks; /* set to 0 initially */
  114. } PCXF;
  115.  
  116. #ifdef _cplusplus
  117. extern "C" {
  118. #endif
  119.  
  120. PCXF  *        fopenPCXr(char *name);
  121. PCXF  *        fopenPCXw(char *name, PCXH *h, char *palette);
  122. int            fseekPCX(PCXF *pcxfile, unsigned y); /* seek scan line y */
  123. int            fclosePCX(PCXF *pcxfile);
  124.  
  125. int   fread8PCX(char *d, unsigned dw, unsigned dl,
  126.                 unsigned dx, unsigned dy,
  127.                 unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p);
  128.  
  129. /* fdisp8PCX may be used in VESA modes with no additional work         */
  130. /* (other than  setting the mode) !!                        */
  131. int   fdisp8PCX(unsigned dx, unsigned dy,
  132.                 unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p);
  133.  
  134. /* fread4PCX reads and converts pixels into a 1 pixel/1 byte format, suitable
  135.    for conversion to a different format */
  136. int   fread4PCX(char *d, unsigned dw, unsigned dl,
  137.                 unsigned dx, unsigned dy,
  138.                 unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p);
  139. /* fdisp4PCX reads and displays in a VGA planar format */
  140. int   fdisp4PCX(unsigned dx, unsigned dy,
  141.                 unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p);
  142.  
  143. /* This function for monochrome .pcx files is untested!  I don't have     */
  144. /* any mono pcx files to test it with (I'm not interested in mono files). */
  145. int   fread1PCX(char *d, unsigned dw, unsigned dl, unsigned dx, unsigned dy,
  146.                 unsigned x0, unsigned y0, unsigned x1, unsigned y1, PCXF *p);
  147.  
  148.  
  149. /* low-level read/write */
  150. unsigned       _read_pcx_line(PCXF *pointer, char * linebuffer,
  151.                               unsigned x0, unsigned x1);
  152. unsigned       _write_pcx_line(PCXF *pointer, char * linebuffer,
  153.                                unsigned x0, unsigned x1,
  154.                                unsigned char fill);
  155.  
  156. void           _write_pcx_palette(PCXF *pointer);
  157. void           _read_palette(PCXF *p);
  158.  
  159.  
  160. void           Start_pcxdebug(char *path);
  161. void           Close_pcxdebug(void);
  162.  
  163. #ifdef _cplusplus
  164. }
  165. #endif
  166.  
  167. #ifdef   PCX_LIB
  168.                 int  PCXerror=0;
  169.                 FILE *pcxdebug;
  170.                 int  debugtimeson=0;
  171. #else
  172.          extern int  PCXerror;
  173.          extern FILE *pcxdebug;
  174.          extern int  debugtimeson;
  175. #endif
  176.  
  177. #endif   /* PCX_lib */
  178.  
  179.  
  180.  
  181. 
  182.